---
title: Test whether bytes are a PDF
summary: Reports whether a byte array carries a PDF signature.
status: draft
owner: SAIF Doc Gen
last_reviewed: 2026-09-17
library: PdfAPI.Core
reference_type: package
operation_id: OP-03
trigger: PdfClientService.IsPdf(byte[]) invoked
---

# Test whether bytes are a PDF

This operation is the low-level signature test used by every other guarded operation in `PdfClientService`, including [Validate PDF bytes](op-01-validate-pdf-bytes.md).

| Field | Value |
| --- | --- |
| **Operation ID** | OP-03 |
| **Trigger** | Caller invokes `IsPdf(byte[] file)` |
| **Inputs** | Byte array |
| **Outputs** | `true` / `false` |
| **Primary components** | `PdfAPI.Core.PdfClientService.IsPdf` |
| **Entry point** | `PdfAPI.Core\Services\PdfClientService.cs` |

## Steps

1. Return `false` when the argument is null. ([BR-02](../business-rules.md#br-02-null-bytes-are-never-a-pdf))
2. Decode the whole byte array as ASCII into a header string.
3. Require length ≥ 5 and the first four bytes to be `0x25 0x50 0x44 0x46` (`%PDF`). ([BR-01](../business-rules.md#br-01-pdf-signature-validation))
4. Return whether the decoded header starts with `"%PDF-"`. ([BR-01](../business-rules.md#br-01-pdf-signature-validation))

## Process flow

The following diagram visualizes this operation's control flow.

```mermaid
flowchart TD
	Start(["IsPdf(bytes)"]) --> Null{bytes null?}
	Null -->|Yes| False1([Return false])
	Null -->|No| Decode["Decode ASCII header"]
	Decode --> Len{length >= 5 and<br>starts with %PDF?}
	Len -->|No| False2([Return false])
	Len -->|Yes| Header{Header starts<br>with "%PDF-"?}
	Header -->|No| False3([Return false])
	Header -->|Yes| True([Return true])
```

## Failure and edge-case behavior
- Decoding the entire byte array as ASCII before inspecting only the first few bytes roughly doubles peak memory per call, which can pressure memory on large documents.*

> **Note:** Statements marked with `*` were inferred from code structure, naming
> conventions, or contextual evidence where direct confirmation was not available
> in source artifacts.

## Related documentation
- [Operations and processes](../operations-processes.md)
- [Business rules](../business-rules.md)
- [Security and authorization](../security-authorization.md)

## Sources
- `PdfAPI.Core\Services\PdfClientService.cs`
